<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Resources;

use App\Services\AttachmentService;
use Illuminate\Support\Carbon;

/**
 * 文章模块资源
 * Class InfoNewsResource
 * @package App\Http\Resources
 */
class InfoNewsResource extends BaseResource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return $this->filterFields([
            // 信息主表_info
            'id' => $this->id,
            'title' => $this->title,
            'subtitle' => $this->subtitle,
            'keywords' => trim($this->keywords) ? explode(",", $this->keywords) : [],
            'description' => $this->description,
            'cover_image' => AttachmentService::previewList($this->cover_image),
            'href' => $this->href,
            'href_target' => $this->href_target,
            'rel' => $this->rel,
            'hits' => $this->hits,
            'recommend_type' => trim($this->recommend_type) ? explode(",", $this->recommend_type) : [],
            'top' => $this->top,
            'status' => $this->status,
            'created_user_name' => ($this->user ? $this->user->name : ''),
            'created_at' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : "",
            'updated_at' => $this->updated_at ? $this->updated_at->format('Y-m-d H:i:s') : "",
            // 文章模型表_info_news
            'source' => $this->infoNews->source,
            'author' => $this->infoNews->author,
            'content' => $this->infoNews->content,
        ]);
    }
}
